package com.leyou.auth.feign;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.task.AppTokenHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * feign的拦截器
 */
@Component
public class PrivilegeInterceptor implements RequestInterceptor {

    @Autowired
    private JwtProperties prop;

    @Autowired
    private AppTokenHolder appTokenHolder;

    @Override
    public void apply(RequestTemplate template) {
        // 每次feign在请求之前，往头中加入token
        template.header(prop.getApp().getHeaderName(), appTokenHolder.getToken());
    }
}
